home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / processes / mp threaded sort / splashwindow.cp < prev    next >
Encoding:
Text File  |  2000-09-28  |  2.7 KB  |  97 lines

  1. /*
  2.     File:        SplashWindow.cp
  3.  
  4.     Contains:    a simple splash screen window
  5.  
  6.     Written by: Dave Falkenburg    
  7.  
  8.     Copyright:    Copyright © 1993-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/27/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 11/16/94    DRF                Add (StringPtr) cast to make PPCC happier.
  21.                 11/12/94    DRF                Use NewColorOrBlackAndWhiteWindow.
  22.                  11/8/94    DRF                Deal with a missing splash picture.
  23.                  9/27/94    DRF                 AppLib.h is now Sprocket.h
  24.                   9/9/94    DRF                Reordered headers and removed redundant #includes.
  25.  
  26. */
  27.  
  28. #include "Sprocket.h"
  29. #include "SplashWindow.h"
  30.  
  31. #include <ToolUtils.h>
  32. #include <Resources.h>
  33.  
  34.  
  35. TSplashWindow::TSplashWindow()
  36.     {
  37.     this->CreateWindow(kNormalWindow);
  38.     }
  39.  
  40.  
  41. TSplashWindow::~TSplashWindow()
  42.     {
  43.     if (fSplashPicture)
  44.     {
  45.         SetWindowPic(fWindow,NULL);
  46.         DisposeHandle((Handle) fSplashPicture);
  47.     }
  48.  
  49.     this->Close();
  50.     }
  51.  
  52.  
  53. WindowPtr
  54. TSplashWindow::MakeNewWindow(WindowPtr behindWindow)
  55.     {
  56.     GrafPtr        oldPort;
  57.     Rect        splashPictRect,windowRect;
  58.     WindowPtr    splashWindow;
  59.     
  60.     GetPort(&oldPort);
  61.  
  62.     fSplashPicture = GetPicture(kSplashPictureID);
  63.     
  64.     if (fSplashPicture)
  65.         {
  66.         MoveHHi((Handle) fSplashPicture);                        //    get it out of the way
  67.         splashPictRect = (**fSplashPicture).picFrame;
  68.         }
  69.     else
  70.         SetRect(&splashPictRect,0,0,0,0);
  71.         
  72.     //    normalize the rectangle
  73.     OffsetRect(&splashPictRect,-splashPictRect.left,-splashPictRect.top);
  74.  
  75.     //    center it on the main screen
  76.     windowRect = splashPictRect;
  77.     OffsetRect(&windowRect,((qd.screenBits.bounds.right-windowRect.right) >> 1),((qd.screenBits.bounds.bottom-windowRect.bottom) >> 1));
  78.     
  79.     splashWindow = NewColorOrBlackAndWhiteWindow(nil,&windowRect,(StringPtr) "\p",false,dBoxProc,behindWindow,false,(long) this);
  80.  
  81.     if (fSplashPicture)
  82.         {
  83.         DetachResource((Handle) fSplashPicture);    // need to do so we don’t botch the resource map after closing
  84.         SetWindowPic(splashWindow,fSplashPicture);    // in case an Alert comes up
  85.         }
  86.         
  87.     ShowWindow(splashWindow);
  88.     SetPort(splashWindow);
  89.     BeginUpdate(splashWindow);                    //    avoid a flashing update event later
  90.         if (fSplashPicture)
  91.             DrawPicture(fSplashPicture,&splashPictRect);
  92.     EndUpdate(splashWindow);                    //    avoid a flashing update event later
  93.  
  94.     SetPort(oldPort);
  95.     return splashWindow;
  96.     }
  97.